<?php
// +---------------------------------------------------------------------------+
// | This file is part of the KnowledgebasePublisher package                   |
// | KnowledgebasePublisher - web based knowledgebase publisher tool           |
// |                                                                           |
// | Author:  Evgeny Leontev <eleontev@gmail.com>                              |
// | Copyright (c) 2005 Evgeny Leontev                                         |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

class KBClientAction_login extends KBClientAction_common
{

	function &execute($controller, $manager) {
	
		// check if registration is not required
		if(!$manager->use_registration) {
			$controller->go();
		}
		
		$view = &$controller->getView('login');

		
		$msg_id = $view->msg_id;
		$view->msg_id = false;
		if(!isset($this->rp->submit)) {
			$authtime = (strpos($msg_id, 'authtime') !== false);
			if(in_array($msg_id, array_keys($view->login_msg)) || $authtime) {
				$msg_id_1 = ($authtime) ? 'authtime' : $msg_id;
				$view->msg_id = $view->login_msg[$msg_id_1];
			}	
		}		
		
		if(isset($this->rp->submit)) {
			
			$errors = $view->validate($this->rp->vars, $manager);
			
			if($errors) {
				$this->rp->stripVars(true);
				$view->setErrors($errors);
				$view->setFormData($this->rp->vars);
			
			} else {
				$view_id = str_replace(array('authtime_', 'category', '_'), '', $msg_id);
				$controller->go($view_id, $this->category_id, $this->entry_id);
			}
		}
		
		return $view;
	}
	
}
?>